package tk.mybatis.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.springboot.mapper.DeptMapper;
import tk.mybatis.springboot.model.Dept;
import tk.mybatis.springboot.model.Message;
import tk.mybatis.springboot.model.Users;

/**
 * Created by  on 2017/4/12.
 */
@RestController
@RequestMapping("/dept")
@Transactional
public class DeptController {

    @Autowired
    private DeptMapper deptMapper;

    @RequestMapping("/add")
    public Object add(Dept obj){
        if(null == obj.getId()) {
            deptMapper.insertSelective(obj);
        }
        else{
            deptMapper.updateByPrimaryKeySelective(obj);
        }
        return new Message();
    }
    @RequestMapping("")
    public Object list(Model model){
       return new Message(deptMapper.selectAll());
    }
    @RequestMapping("/delete/{id}")
    public Object delete(@PathVariable Integer id){
        deptMapper.deleteByPrimaryKey(id);
        return new Message();
    }


}
